import { Controller, Body, Get, Post, Param } from '@nestjs/common';

import { UsersService } from './users.service';
import { User, UserDto } from '../../entities';

interface Result<T> {
  success: boolean;
  value: T;
}

@Controller()
export class UsersController {

  constructor(private usersService: UsersService) {}

  /** 查询所有用户 */
  @Get('/all-users')
  findAll(): Promise<Result<User[]>> {
    return this.usersService.findAll();
  }

  /** 根据邮箱查询用户 */
  @Get('/userEmail/:email')
  findOne(
    @Param() email: string
  ): Promise<Result<User>> {
    return this.usersService.findOne(email);
  }

  /** 根据uid查询用户 */
  @Get('/userId/:uid')
  findOneById(
    @Param() uid: string
  ): Promise<Result<User>> {
    return this.usersService.findOneById(uid);
  }

  /** 根据uid数组查询 */
  @Post('/userIds')
  findUsersByIds(
    @Body() uid: any[]
  ): Promise<Result<User[]>> {
    return this.usersService.findUsersByIds(uid);
  }

}